package com.test.nnooolwdeaer.dialog_wooden;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.os.Bundle;
import android.widget.Button;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.test.nnooolwdeaer.R;
import com.test.nnooolwdeaer.activity_fragment_wooden.base_wooden.BaseActivity_wooden;
import com.test.nnooolwdeaer.util_wooden.helper_wooden.UserInfoHelper_wooden;
import com.test.nnooolwdeaer.activity_fragment_wooden.login_wooden.LoginPhoneNumActivity_wooden;

public class LogoutDialog_wooden extends Dialog {

    private final BaseActivity_wooden activity_wooden;

    public LogoutDialog_wooden(@NonNull BaseActivity_wooden activity) {
        super(activity);
        this.activity_wooden = activity;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_logout_wooden);
        initView_wooden();
    }

    @SuppressLint("SetTextI18n")
    private void initView_wooden(){

        getWindow().setBackgroundDrawableResource(R.color.trans);

        ((TextView)findViewById(R.id.dialog_logout_tv_title)).setText("Log out");
        ((TextView)findViewById(R.id.dialog_logout_tv_explain)).setText("Are you sure you want to log out of your account?");

        Button cancelBtn = findViewById(R.id.dialog_logout_btn_cancel);
        Button logoutBtn = findViewById(R.id.dialog_logout_btn_submit);
        cancelBtn.setText("Cancel");
        logoutBtn.setText("Log out");
        cancelBtn.setTextColor(getContext().getColor(R.color.black));
        logoutBtn.setTextColor(getContext().getColor(R.color.gray_dd));
        //取消
        cancelBtn.setOnClickListener(view -> {
            dismiss();
        });
        //退出登录
        logoutBtn.setOnClickListener(view -> {
            dismiss();
            //删除本地登录信息
            UserInfoHelper_wooden.getInstance_wooden().setMobile_wooden("");
            UserInfoHelper_wooden.getInstance_wooden().setToken_wooden("");
            UserInfoHelper_wooden.getInstance_wooden().setUserId_wooden("");
            activity_wooden.startActivityForSingleTop_wooden(LoginPhoneNumActivity_wooden.class);
        });
        setCanceledOnTouchOutside(false);
    }
}
